package basic.lessons;

import java.awt.Color;
import java.awt.Graphics;

public class ChessBoardMoving extends SimpleAnimationApplet2
{
	public void drawFrame(Graphics g) {

        // Draw a set of nested black rectangles on a red background.
        // Each nested rectangle is separated by 15 pixels on
        // all sides from the rectangle that encloses it.
        
     int insetW= 0;   // inset by width 
     int insetH= 0;    // inset by height    
     
     

//     g.setColor(Color.red);
//     g.fillRect(insetW,insetH,20,20);  // Fill the square applet with red.
//     
//     g.setColor(Color.black);
//     g.fillRect(insetW,insetH,20,20);  // Fill the square applet with black.
    	for (int i = 1; i <= 8; i++) {
			for (int j = 1; j <= 12; j++) {
				if ((j + i) % 2 == 0) {
					if (i%2!=0){
						g.setColor(Color.black);
						g.fillRect(insetW+getFrameNumber()%40, insetH, 20, 20);
						insetW += 20;
					}
					else {
					g.setColor(Color.black);
					g.fillRect(insetW-getFrameNumber()%40, insetH, 20, 20);
					insetW += 20;
					}
				} else {
					if (i%2!=0){
					g.setColor(Color.red);
					g.fillRect(insetW+getFrameNumber()%40, insetH, 20, 20);
					insetW += 20;
					}
					else {
						g.setColor(Color.red);
						g.fillRect(insetW-getFrameNumber()%40, insetH, 20, 20);
						insetW += 20;
					}
				}
			}
			insetH += 20;
			insetW = 0;
		}

	}
     

}

